/**
* 
* 
*  
*====================================================
* 文件名称: JexlServletContext.java
* 修订记录：
* No    日期				作者(操作:具体内容)
* 1.    2011-2-24			
*====================================================
* 类描述：(说明未实现或其它不应生成javadoc的内容)
* 
*/
package com.devframe.web.util.jexl;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.jexl2.JexlContext;

/**
 *<pre><b><font color="blue">JexlServletContext</font></b></pre>
 *
 *<pre><b>&nbsp;--描述说明--</b></pre>
 * <pre></pre>
 * <pre>
 * <b>--样例--</b>
 *   JexlServletContext obj = new JexlServletContext();
 *   obj.method();
 * </pre>
 * JDK版本：JDK1.4
 * @author  <b></b> 
 */
public class JexlServletContext implements JexlContext {
    private HttpServletRequest request;
    public JexlServletContext(HttpServletRequest request){
        this.request = request;
    }

    /**
     * @param name
     * @return
     * 
     */
    public Object get(String name) {
        Object result = request.getAttribute(name);
        if(result==null){
            result=request.getSession().getAttribute(name);
        }
        if(result==null){
            result=request.getSession().getServletContext().getAttribute(name);
        }
        return result;
    }

    /**
     * @param name
     * @return
     * 
     */
    public boolean has(String name) {
        return get(name)!=null;
    }

    /**
     * @param name
     * @param value
     * 
     */
    public void set(String name, Object value) {
        request.setAttribute(name, value);
    }

}
